package com.ruoyi.produce.process.scheduling.util;

import com.ruoyi.produce.process.scheduling.domain.Scheduling;

import java.util.*;

/**
 * 排产工具类
 */
public class SchedulingUtil {
    public static void main(String[] args) {
    }

    /**
     * 更新优先级
     */
    public static List<Scheduling> updatePriority(List<Scheduling> schedulingList) {
        List<Scheduling> resList = new ArrayList<>();
        int length = schedulingList.size();
        Deque<Scheduling> stack1 = new ArrayDeque<>(); //存放最后返回的数据
        Deque<Scheduling> stack2 = new ArrayDeque<>(); //临时改优先级的栈
        for (int i = 0; i < length; i++) {
            stack1.push(schedulingList.get(i)); //添加到s1
        }
        for (int i = 0; i < length - 1; i++) {
            Scheduling s = stack1.pop();
//            s.setPriority(length - 1 - i);
            stack2.push(s);
        }
        while (!stack2.isEmpty()) {
            resList.add(stack2.pop());
        }
        Scheduling scheduling = stack1.pop();//最后弹出的是最后要改的优先级
//        scheduling.setPriority(length);
        resList.add(scheduling);

        return resList;
    }
}

